import unittest
import sys,  os
from pylab import *
sys.path.append( os.getcwd() )
from pozonoperm import *


class TestPozoNoPerm(unittest.TestCase):
  def setUp(self):    
    # Custodio Semiconfinado
    self.r = 10
    ti = self.generaRangoLog(0.001, 1000, 60)
    self.t = []
    self.u = []
    self.iu = []
    # self.s = []
    self.Q = 60*60*60*24/1000
    self.T = 1000
    self.S = 0.0001     
    for tt in ti:
      self.t.append(tt/24.0/60.0)
    for tt in self.t:
      self.u.append( (self.r**2)*self.S/(4*self.T*tt) ) 
      self.iu.append( 1.0/(self.r**2)*self.S/(4*self.T*tt) )           
    self.rdb = self.generaRangoLog(0.01, 3.0, 30)
    self.pnp = PozoNoPerm()
  
  def generaRangoLog(self, li, lf, n):
    """
    Genera intervalos equilog 
  
    La decripcion larga
  
    Parameters
    -----------------
    li : float
      Limite inferior
    lf : float
      Limite superior      
    n : float
      Nuero de intervalos en el rango
    """    
    # from math import *
    import matplotlib as mpl
    mpl.rcParams['font.family'] = 'Arial'
    mpl.rcParams['font.size'] = 6
    b = []
    kk = ( lf/li )**(1.0/n)
    for i in range(0, n+1):
      b.append( li*kk**i )
    return ( b )
    
  def testcalcDescASC(self):
    for rdb in self.rdb:
      self.s = self.pnp.descASC(self.r, self.t, self.Q, self.T, self.S, rdb)
      loglog(self.t, self.s, label="r/B=%.2E" % rdb)
    xlabel = "t(d)"
    ylabel = "W(u,a)"
    grid(True)
    legend()
    import random
    string = ''
    for i in range(9):
      string += random.choice('abcdefghijklmnopqrstuvwxyz0123456789_-ABCDEFGHIJKMLNOPQRSTUVWXYZ')
    string += ".pdf"
    string = "/tmp/" + string  
    savefig(string,dpi=(1024/8))
    
if __name__ == '__main__':
    unittest.main()
